<?php
session_start();
include "./conexao.php";
$usid = $_SESSION['id'];
$select = "SELECT c.ytid, c.yttitulo, c.ytminiatura, c.ytusername FROM inscricao i, canal c WHERE i.ytid = c.ytid AND i.usid = '$usid' ORDER BY i.ytid";
$res = mysql_query($select);
$feed = "";
while($row = mysql_fetch_array($res)){
	$videos = mysql_query("SELECT v.vdlabel, v.vdtitulo FROM video v WHERE v.ytid = ".$row['ytid']." ORDER BY v.vdid DESC LIMIT 30");
	$feed = $feed."<div class=\"col-sm-12\">";
	$feed = $feed."<img src=\"http://".$row['ytminiatura']."\" width=\"30\" height=\"30\" style=\"float:left;margin-right:10px;\">";
	$feed = $feed."<h4>".$row['yttitulo']."</h4>";
	$feed = $feed."<section id=\"".$row['ytusername']."\" class=\"carousel slide\" data-ride=\"carousel\" data-interval=\"false\"><div class=\"carousel-inner\">";
	$fimF = true;
	$a = "active";
	while($fimF){
		$item = "";
		for ($i=0; $i < 5; $i++) { 
			if($v = mysql_fetch_array($videos)){
				$item = $item."<div class=\"col-sm-2\"><a href=\"http://facetube.esy.es/watch.php?v=".$v['vdlabel']."\"><img class=\"img-responsive\" src=\"//i.ytimg.com/vi/".$v['vdlabel']."/mqdefault.jpg\"><h6>".$v['vdtitulo']."</h6></a></div>";
			}else{
				$fimF = false;
				break;
			}
		}
		if($fimF == false){break;}
		$feed = $feed."<div class=\"item ".$a."\" data-thumb=\"0\"><div class=\"col-sm-1\"></div>".$item;
		$a = "";
		
		$feed = $feed."</div>";
	}
	$feed = $feed."</div><a href=\"#".$row['ytusername']."\" class=\"left carousel-control\" data-slide=\"prev\">
                  <img src=\"http://facetube.esy.es/img/left.png\" alt=\"\" width=\"30\" height=\"30\">
                </a><a href=\"#".$row['ytusername']."\" class=\"right carousel-control\" data-slide=\"next\">
                  <img src=\"http://facetube.esy.es/img/right.png\" alt=\"\" width=\"30\" height=\"30\">
                </a></section><br>";
}
if($feed == NULL){
	$feed = "ERRO";
}
echo $feed;
?>